#ifndef __GC0307_H__
#define __GC0307_H__

#if 0
unsigned char gc0307_YCbCr8bit[][2] = {
	{0x48, 0x80},
	{0x43, 0x00},
	{0x31, 0x00},

	{0x0E, 0x00},
	{0x01, 0xC8},

	//AEC

	{0x03, 0x01},
	{0x04, 0x85},
	{0xDB, 0x3c},
	{0xDC, 0x40},

	//Contrast
	{0xA1, 0x90},
	{0x77, 0x80},
	{0x40, 0x1E},
	{0x41, 0x01},
	{0x42, 0x00},
	{0x43, 0x40},
	{0x44, 0xF1},
	{0x45, 0x25},
	{0x47, 0x04},
	{0x49, 0x00},
	{0x4A, 0x00},
	{0x4B, 0x00},
	{0x4D, 0x1B},
	{0x4E, 0x1F},
	{0x4F, 0x01},
	{0x0F, 0x22},

	//Window
	{0x05, 0x00},
	{0x06, 0x00},
	{0x07, 0x00},
	{0x08, 0x40},
	{0x09, 0x01},
	{0x0A, 0xe8},
	{0x0B, 0x02},
	{0x0C, 0x80},

	//power down off
	{0x13, 0x80},
};
#else
unsigned char gc0307_YCbCr8bit[][2] = {
	// Initail Sequence Write In.
	//========= close output
	{0xf0,0x00},
	{0x43,0x00},
//	{0x44,0xa2},
	{0x44,0xe6},

	//========= close some functions
	// open them after configure their parmameters
//	{0x40,0x10},
//	{0x41,0x00},//08
//	{0x42,0x10},
//	{0x47,0x00},//mode1,
	
	{0x40,0x7e},
	{0x41,0x2f},
	{0x43,0x40},
//	{0x44,0xE2},
	{0x44,0xE6},

	{0x45, 0x26},
	{0x47, 0x28},
	
	{0x48,0xc7},//mode2, 0xc1
	{0x49,0x00},//dither_mode
	{0x4a,0x00},//clock_gating_en
	{0x4b,0x00},//mode_reg3
	{0x4E,0x23},//sync mode 23 20120410
	{0x4F,0x01},//AWB, AEC, every N frame 01

	//========= frame timing

	{0x1C,0x00},//Vs_st
	{0x1D,0x00},//Vs_et

	{0x11,0x05},//row_tail, AD_pipe_number

	{0x03,0x01},//row_start
	{0x04,0x2c},

	//========= windowing
	{0x05,0x00},//row_start
	{0x06,0x00},
	{0x07,0x00},//col start
	{0x08,0x00},
	{0x09,0x01},//win height
	{0x0A,0xea},//ea 0xe8 james
	{0x0B,0x02},//win width, pixel array only 640
	{0x0C,0x80},//0x80

	//========= analog
	{0x0D,0x22},//rsh_width
	{0x0E,0x02},//CISCTL mode2,
	{0x0F,0xa2},//CISCTL mode1


	{0x12,0x70},//7 hrst, 6_4 darsg,
	{0x13,0x00},//7 CISCTL_restart, 0 apwd

	{0x14,0x00},//NA
	{0x15,0xba},//7_4 vref
	{0x16,0x13},//5to4 _coln_r, __1to0__da18
	{0x17,0x52},//opa_r, ref_r, sRef_r
//	{0x18,0xc0},//analog_mode, best case for left band.
	{0x18,0x00},

	{0x1E,0x0d},//tsp_width
	{0x1F,0x32},//sh_delay

	//========= offset
	//{0x47,0x00}, //7__test_image, __6__fixed_pga, //__5__auto_DN,__4__CbCr_fix,
	//__3to2__dark_sequence, __1__allow_pclk_vcync, __0__LSC_test_image
	{0x19,0x06}, //pga_o
	{0x1a,0x06}, //pga_e

	{0x31,0x00}, //4 //pga_oFFset , high 8bits of 11bits
	{0x3B,0x00}, //global_oFFset, low 8bits of 11bits
     
	{0x59,0x0f}, //offset_mode
	{0x58,0x88}, //DARK_VALUE_RATIO_G, DARK_VALUE_RATIO_RB
	{0x57,0x08}, //DARK_CURRENT_RATE
	{0x56,0x77}, //PGA_OFFSET_EVEN_RATIO, PGA_OFFSET_ODD_RATIO

	//========= blk
	{0x35,0xd8}, //blk_mode

	{0x36,0x40},

	{0x3C,0x00},
	{0x3D,0x00},
	{0x3E,0x00},
	{0x3F,0x00},

	{0xb5,0x70},
	{0xb6,0x40},
	{0xb7,0x00},
	{0xb8,0x38},
	{0xb9,0xc3},
	{0xba,0x0f},

	{0x7e,0x45},
	{0x7f,0x66},

	{0x5c,0x38},//78 48
	{0x5d,0x48},//88 58
      
      
	//========= manual_gain
	{0x61,0x80},//manual_gain_g1
	{0x63,0x80},//manual_gain_r
	{0x65,0x98},//manual_gai_b, 0xa0=1.25, 0x98=1.1875
	{0x67,0x80},//manual_gain_g2
	{0x68,0x18},//global_manual_gain 2.4bits

	//=========CC _R
	{0x69,0x58}, //54//58
	{0x6A,0xf6}, //ff
	{0x6B,0xfb}, //fe
	{0x6C,0xf4}, //ff
	{0x6D,0x5a}, //5f
	{0x6E,0xe6}, //e1

	{0x6f,0x00},

	//=========lsc
	{0x70,0x14},
	{0x71,0x1c},
	{0x72,0x20},

	{0x73,0x10},
	{0x74,0x3c},//480/8
	{0x75,0x52},//640/8

	//=========dn
	{0x7d,0x2f},//dn_mode
	{0x80,0x0c},//when auto_dn, check 7e,7f
	{0x81,0x0c},
	{0x82,0x44},
                  
	//dd
	{0x83,0x18}, //DD_TH1
	{0x84,0x18}, //DD_TH2
	{0x85,0x04}, //DD_TH3
	{0x87,0x34}, //32 b DNDD_low_range X16, DNDD_low_range_C_weight_center

	//=========intp-ee
	{0x88,0x04},
	{0x89,0x01},
	{0x8a,0x50},//60
	{0x8b,0x50},//60
	{0x8c,0x07},

	{0x50,0x0c},
	{0x5f,0x3c},

	{0x8e,0x02},
	{0x86,0x02},

	{0x51,0x20},
	{0x52,0x08},
	{0x53,0x00},

	//========= YCP
	//contrast_center
	{0x77,0x80},//contrast_center
	{0x78,0x00},//fixed_Cb
	{0x79,0x00},//fixed_Cr
	//{0x7a,0x00},//luma_offset
	{0x7b,0x40},//hue_cos
	{0x7c,0x00},//hue_sin

	//saturation
	{0xa0,0x40},//global_saturation\
	{0xa1,0x40},//luma_contrast
	{0xa2,0x40},//saturation_Cb//0x34
	{0xa3,0x40},// 34 saturation_Cr//0x34
          
	{0xa4,0xc8},
	{0xa5,0x02},
	{0xa6,0x28},
	{0xa7,0x02},

	//skin
	{0xa8,0xee},
	{0xa9,0x12},
	{0xaa,0x01},
	{0xab,0x20},
	{0xac,0xf0},
	{0xad,0x10},

	//========= ABS
	{0xae,0x18},// black_pixel_target_number
	{0xaf,0x74},
	{0xb0,0xe0},
	{0xb1,0x20},
	{0xb2,0x6c},
	{0xb3,0x40},
	{0xb4,0x04},

	//========= AWB
	{0xbb,0x42},
	{0xbc,0x60},
	{0xbd,0x50},
	{0xbe,0x50},

	{0xbf,0x0c},
	{0xc0,0x06},
	{0xc1,0x60},
	{0xc2,0xf1},//f4
	{0xc3,0x40},
	{0xc4,0x1c},//18
	{0xc5,0x56},
	{0xc6,0x1d},

	{0xca,0x70},//0x70
	{0xcb,0x6a},//0x70
	{0xcc,0x70},//0x78

	{0xcd,0x80},//R_ratio 0x80
	{0xce,0x80},//G_ratio , cold_white white
	{0xcf,0x86},//B_ratio 0x80

	//========= aecT
	{0x20,0x06},//02
	{0x21,0xc0},
	{0x22,0x40},
	{0x23,0x88},
	{0x24,0x96},
	{0x25,0x30},
	{0x26,0xd0},
	{0x27,0x00},

	/////
	{0x01,0xfa},//HB
	{0x02,0x70},//VB//0c
	{0x10,0x01},//high 4 bits of VB, HB
	{0xd6,0x64},//antiflicker_step //96

	{0x28,0x02},//AEC_exp_level_1bit11to8
	{0x29,0x58},//AEC_exp_level_1bit7to0
	{0x2a,0x02},//AEC_exp_level_2bit11to8
	{0x2b,0x58},//AEC_exp_level_2bit7to0
	{0x2c,0x02},//AEC_exp_level_3bit11to8 659 - 8FPS, 8ca - 6FPS //
	{0x2d,0x58},//AEC_exp_level_3bit7to0
	{0x2e,0x02},//AEC_exp_level_4bit11to8 4FPS
	{0x2f,0x58},//AEC_exp_level_4bit7to0

	{0x30,0x20},
	{0x31,0x00},
	{0x32,0x1c},
	{0x33,0x90},
	{0x34,0x10},

	{0xd0,0x34},//[2] 1 before gamma, 0 after gamma

	{0xd1,0x60},//AEC_target_Y//0x50
	{0xd2,0x61},//f2
	{0xd4,0x4b},//96
	{0xd5,0x01},// 10

	{0xd7,0x03},//AEC_exp_time_min //10
	{0xd8,0x02},

	{0xdd,0x12},

	//========= measure window
	{0xe0,0x03},
	{0xe1,0x02},
	{0xe2,0x27},
	{0xe3,0x1e},
	{0xe8,0x3b},
	{0xe9,0x6e},
	{0xea,0x2c},
	{0xeb,0x50},
	{0xec,0x73},
		  
		         //========= close_frame
	{0xed,0x00},//close_frame_num1 ,can be use to reduce FPS
	{0xee,0x00},//close_frame_num2
	{0xef,0x00},//close_frame_num


// page1 /////////////////////////////////////////////
	{0xf0,0x01},//select page1
		  
	{0x00,0x20},
	{0x01,0x20},
	{0x02,0x20},
	{0x03,0x20},
	{0x04,0x78},
	{0x05,0x78},
	{0x06,0x78},
	{0x07,0x78},
		 
		 
		 
	{0x10,0x04},
	{0x11,0x04},
	{0x12,0x04},
	{0x13,0x04},
	{0x14,0x01},
	{0x15,0x01},
	{0x16,0x01},
	{0x17,0x01},
		  
		  
	{0x20,0x00},
	{0x21,0x00},
	{0x22,0x00},
	{0x23,0x00},
	{0x24,0x00},
	{0x25,0x00},
	{0x26,0x00},
	{0x27,0x00},
		 
	{0x40,0x11},
     
	//=============================lscP
	{0x45,0x08}, // r
	{0x46,0x07}, //g
	{0x47,0x08}, //b

	{0x48,0x04},
	{0x49,0x03},
	{0x4a,0x03},


	{0x62,0xd8},
	{0x63,0x24},
	{0x64,0x24},
	{0x65,0x24},
	{0x66,0xd8},
	{0x67,0x24},

	{0x5a,0x00},
	{0x5b,0x00},
	{0x5c,0x00},
	{0x5d,0x00},
	{0x5e,0x00},
	{0x5f,0x00},


	//============================= ccP

	{0x69,0x03},//cc_mode

	//CC_G
	{0x70,0x5d},
	{0x71,0xed},
	{0x72,0xff},
	{0x73,0xe5},
	{0x74,0x5f},
	{0x75,0xe6},

	//CC_B
	{0x76,0x41},
	{0x77,0xef},
	{0x78,0xff},
	{0x79,0xff},
	{0x7a,0x5f},
	{0x7b,0xfa},


	//============================= AGP
	{0x7e,0x00},
	{0x7f,0x10}, // 30 0x40 select gamma
	{0x80,0x48}, // c8
	{0x81,0x06},
	{0x82,0x08},


	{0x83,0x23},
	{0x84,0x38},
	{0x85,0x4F},
	{0x86,0x61},
	{0x87,0x72},
	{0x88,0x80},
	{0x89,0x8D},
	{0x8a,0xA2},
	{0x8b,0xB2},
	{0x8c,0xC0},
	{0x8d,0xCA},
	{0x8e,0xD3},
	{0x8f,0xDB},
	{0x90,0xE2},
	{0x91,0xED},
	{0x92,0xF6},
	{0x93,0xFD},

	//about gamma1 is hex r oct
	{0x94,0x04},
	{0x95,0x0E},
	{0x96,0x1B},
	{0x97,0x28},
	{0x98,0x35},
	{0x99,0x41},
	{0x9a,0x4E},
	{0x9b,0x67},
	{0x9c,0x7E},
	{0x9d,0x94},
	{0x9e,0xA7},
	{0x9f,0xBA},
	{0xa0,0xC8},
	{0xa1,0xD4},
	{0xa2,0xE7},
	{0xa3,0xF4},
	{0xa4,0xFA},

	//========= open functions
	{0xf0,0x00},//set back to page0     
//	{0x40,0x7e},
//	{0x41,0x2f},
//	{0x43,0x40},
//	{0x44,0xE2},
//	{0x44,0xE6},

//	{0x0f, 0xa2},
//	{0x45, 0x26},
//	{0x47, 0x28},

#if 1
	//AEC
	{0x03, 0x01},
	{0x04, 0x85},
	{0xDB, 0x3c},
	{0xDC, 0x40},

	//Window
	{0x05, 0x00},
	{0x06, 0x00},
	{0x07, 0x00},
	{0x08, 0x00},
	{0x09, 0x01},
	{0x0A, 0xe8},
	{0x0B, 0x02},
	{0x0C, 0x80},
#endif

	{0xff,0xff},
};
#endif

#define GC0307_INIT_REGS (sizeof(gc0307_YCbCr8bit) / sizeof(gc0307_YCbCr8bit[0]))

#endif
